/**
 * Created by 白雨浓 on 2018/1/13 20:26.
 */

import crypto from 'crypto';

export default {
    install(Vue){

        const aesEncrypt = (data, key) => {
            const cipher = crypto.createCipher('aes192', key);
            let crypted = cipher.update(data, 'utf8', 'hex');
            crypted += cipher.final('hex');
            return crypted;
        };

        const aesDecrypt = (encrypted, key) => {
            let decrypted;
            try {
                const decipher = crypto.createDecipher('aes192', key);
                decrypted = decipher.update(encrypted + "", 'hex', 'utf8');
                decrypted += decipher.final('utf8');
            } catch (e) {
                console.log(e);
            }
            return decrypted;
        };


        Vue.prototype.$crypto = {
            aesEncrypt,
            aesDecrypt,
        };
    },
}